package org.hook.showcase.pattern.command.impl;

import org.hook.showcase.pattern.command.Command;

public class SimpleRemoteControl {
	public static final int COMMAND_SIZE = 10;
	private Command[] onCommands;
	private Command[] offCommands;
	private Command undoCommand;

	public SimpleRemoteControl() {
		this.onCommands = new Command[COMMAND_SIZE];
		this.offCommands = new Command[COMMAND_SIZE];
		Command noCommand = new NoCommand();
		for (int i = 0; i < COMMAND_SIZE; i++) {
			this.onCommands[i] = noCommand;
			this.offCommands[i] = noCommand;
		}
		this.undoCommand = noCommand;
	}

	public void onButtonWasPressed(int slot) {
		this.onCommands[slot].execute();
		this.undoCommand = this.onCommands[slot];
	}

	public void offButtonWasPressed(int slot) {
		this.offCommands[slot].execute();
		this.undoCommand = this.offCommands[slot];
	}

	public void undoButtonWasPressed() {
		this.undoCommand.undo();
	}

	public void setCommand(int slot, Command on, Command off) {
		this.onCommands[slot] = on;
		this.offCommands[slot] = off;
	}
}
